package com.fph.design.matter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * 模拟集群 IIR
 * @ClassName IIR
 * @Description TODO
 * @Author fph
 * @Date 2024-07-09 17:15
 **/
public class IIR {
    private Logger logger = LoggerFactory.getLogger(IIR.class);

    private Map<String, String> dataMap = new ConcurrentHashMap<>();

    public String get(String key){
        logger.info("IIR获取数据key：{}", key);
        return dataMap.get(key);
    }

    public String set(String key, String value){
        logger.info("IIR写入数据key：{}，value：{}", key, value);
        return dataMap.put(key, value);
    }

    public String setExpire(String key, String value, long timeout, TimeUnit timeUnit){
        logger.info("IIR写入数据key：{}，value：{}，timeout：{}, timeUnit：{}", key, value, timeout, timeUnit);
        return dataMap.put(key, value);
    }

    public void del(String key){
        logger.info("IIR删除数据key：{}", key);
        dataMap.remove(key);
    }
}

